package qlsl.androiddesign.activity.subactivity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

import com.alibaba.fastjson.JSONObject;
import com.alipay.sdk.pay.demo.PayDemoActivity;
import com.lidroid.xutils.HttpUtils;
import com.qlsl.androiddesign.kuaiwa.R;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import qlsl.androiddesign.activity.commonactivity.SelectCityActivity;
import qlsl.androiddesign.constant.Constant;
import qlsl.androiddesign.entity.commonentity.City;
import qlsl.androiddesign.entity.commonentity.FragmentArgs;
import qlsl.androiddesign.entity.otherentity.OrderResult;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.util.commonutil.Log;
import qlsl.androiddesign.util.commonutil.NetUtils;
import qlsl.androiddesign.util.runfeng.AbJsonUtil;
import qlsl.androiddesign.util.runfeng.NetUtil;
import qlsl.androiddesign.util.runfeng.StringUtils;
import qlsl.androiddesign.util.runfeng.UIUtils;

public class ExChangeOrderActivity extends OrderActivity implements
		OnClickListener {

	protected String goodsid;// 订单信息
	protected String totalprice;// 订单信息

	protected LinearLayout is_address, is_address2, is_address3, wb_guize;

	protected void initData() {
		is_address = (LinearLayout) findViewById(R.id.is_address);
		is_address.setVisibility(View.GONE);
		is_address2 = (LinearLayout) findViewById(R.id.is_address2);
		is_address2.setVisibility(View.GONE);
		is_address3 = (LinearLayout) findViewById(R.id.is_address3);
		is_address3.setVisibility(View.GONE);

		wb_guize = (LinearLayout) findViewById(R.id.wb_guize);
		wb_guize.setVisibility(View.GONE);

		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			FragmentArgs args = (FragmentArgs) bundle
					.getSerializable("goumainBundle");
			goodslist = (String) args.get("goodslist");
			totalprice = (String) args.get("totalprice");
			goodsid = (String) args.get("goodsid");

		}
	}

	public void requestData(final View v) {
		new HandlerThread("ww", "subOrder") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();

				JSONObject jo = protocol
						.setMethod("cashing")
						.addParam("goodslist", goodslist)
						.addParam("consigneeaddress", getDeatilAddress())
						.addParam("consigneearea", getConsigneearea())
						.addParam("consigneecity", consigneecity())

						.addParam("goodsinfoid", goodsid)
						// 商品id
						.addParam("nums", "1")
						// 商品数量
						.addParam("totalpoints", totalprice)
						// 多少挖币

						.addParam("consigneeprovince", consigneeprovince())
						.addParam("consigneemobile", phoneNumber())
						.addParam("consigneename", getUserName()).post();
				mOrderResult = (OrderResult) AbJsonUtil.fromJson(
						jo.toJSONString(), OrderResult.class);
				if (mOrderResult.OK()
						&& NetUtils.isConnected(getApplicationContext())) {
					UIUtils.runOnUIThread(new Runnable() {
						@Override
						public void run() {
							showToast("兑换成功");
							finish();
						}
					});
				} else if (mOrderResult.getErrorCode().equals("40002")) {
					showAsynToast("挖币不够");
				} else {
					showAsynToast("提交订单失败，请重新提交");
				}
			};
		}.start();
	}
}
